<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>基本用法</title>
  <style>
    .wrap {
      width: 1000px;
      height: 800px;
      border: 1px solid #000;
      margin: 20px auto;
      padding: 10px;
    }
  </style>
</head>
<body>
<div class="wrap">
  <h4>
    canvas 只有两个属性 width height
  </h4>

  <canvas id="canvas" width="150" height="150"></canvas>

</div>

</body>
</html>

<script>
  function draw() {
    let canvas = document.getElementById("canvas");

    if (canvas.getContext) {
      let ctx = canvas.getContext("2d");

      ctx.fillStyle = "rgb(200,0,0)";
      ctx.fillRect(10, 10, 55, 50);

      ctx.fillStyle = "rgba(0, 0, 200, 0.5)";
      ctx.fillRect(30, 30, 55, 50);
    }
  }
  draw();
</script>